#!/bin/bash
#
#$ -cwd
#$ -j y
#$ -S /bin/bash
#
###############################################
###### IRIS-Processor #########################
###############################################

# This script processes an iris-database the following way
# Input Image 	=> Segmentation result (<filename>.png)
#		=> Iris code	       (<filename>.png)


DIST=$1
TARGET=$2		# The folder to the specific itexfolder, e.g. ic/qsw/

if [ $# -ne 2 ] ; then

echo 'Call with two parameters:'
echo 'first: distance tool as in bin-directory, i.e. hd'
echo 'second: directory, where an ic folder resides (inside an ic/<directoryName>.dist.csv file is going to be generated)'

exit
fi



FOLDER=`dirname $TARGET`
TARGET_IC=$FOLDER
TOOLDIR=bin

CSVNAME=${TARGET/$TARGET_IC/}

CSVNAME=${CSVNAME/\//}
CSVNAME=${CSVNAME/\//}.dist.csv


OUTFILE=$TARGET_IC/$CSVNAME


echo 'going to work in ' $TARGET_IC
echo 'Storing distances to ' $OUTFILE



 # Clean up
 FILELIST=`ls $TARGET`

      echo 'F1','F2','distance', > $OUTFILE

       for F in $FILELIST
       do
          echo $TARGET ': Processing distances to ' $F
          for FF in $FILELIST
          do

              RES=`$TOOLDIR/$DIST -i $TARGET/$F $TARGET/$FF`
                            

              IFS='=' read -a PARTS <<< "$RES"

            

              echo $F,$FF,${PARTS[1]} >> $OUTFILE

          done
       done
